#多线程中的锁
import threading
VALUE = 0
gLock = threading.Lock()

def add_value():
    global VALUE
    gLock.acquire() #获取锁
    for x in range(500000):
        VALUE += 1
    gLock.release() #释放线程锁，允许其他线程获取。
    print('value：%d' % VALUE)

def main():
    for x in range(2):
        t = threading.Thread(target=add_value)
        t.start()
   
if __name__ == '__main__':
    main()